package com.oma.testcase;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Search_Applicant {
	
	private static String referenceNum;

	public void search(WebDriver driver, String refNum) throws Exception {
		
		boolean checker = false;
		referenceNum = refNum;
		
		//Applicant's Table
		List<WebElement> rows = driver.findElements(By.xpath("//table[@id='DataTables_Table_0']/tbody/tr"));
		int size = rows.size();
		
		for(int x=0; size>x; size--)
		{
			String listrefNum = driver.findElement(By.xpath("//table[@id='DataTables_Table_0']/tbody/tr["+size+"]/td[1]")).getText(); // get refnum of row
			
			if(referenceNum.equals(listrefNum))
			{
				checker = true;
				System.out.println("Displayed account of: " +refNum);
				break;
			}
			
		}
		
		if(checker == true)
		{
			driver.findElement(By.xpath("//table[@id='DataTables_Table_0']/tbody/tr["+size+"]/td[9]/a")).click(); //click eye button
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		} else {
			driver.findElement(By.xpath("//a[@id='DataTables_Table_0_next']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			search(driver, referenceNum);
		}
	}
	
}
